<?php

Yii::import('common.models.db._base.BaseDeliveryCustomerModel');

class DeliveryCustomerModel extends BaseDeliveryCustomerModel
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	public function attributeLabels() {
		return array(
				'id' => Yii::t('app', 'ID'),
				'code' => Yii::t('DeliveryModule.main', 'Code'),
				'name' => Yii::t('DeliveryModule.main', 'Name'),
				'address' => Yii::t('DeliveryModule.main', 'Address'),
				'billing_address' => Yii::t('DeliveryModule.main', 'Billing Address'),
				'mst' => Yii::t('DeliveryModule.main', 'MST'),
				'phone' => Yii::t('DeliveryModule.main', 'Phone'),
				'fax' => Yii::t('DeliveryModule.main', 'Fax'),
				'person_contact' => Yii::t('DeliveryModule.main', 'Person Contact'),
				'email' => Yii::t('DeliveryModule.main', 'Email'),
				'office_offer' => Yii::t('DeliveryModule.main', 'Office Offer'),
				'office_person' => Yii::t('DeliveryModule.main', 'Office Person'),
				'created_datetime' => Yii::t('DeliveryModule.main', 'Created Datetime'),
				'updated_datetime' => Yii::t('DeliveryModule.main', 'Updated Datetime'),
				'status' => Yii::t('DeliveryModule.main', 'Status'),
		);
	}
	public function beforeSave()
	{
		$this->updated_datetime = new CDbExpression('NOW()');
		return parent::beforeSave();
	}
	public function getCusByTicket($ticketCode)
	{
		$sql = "SELECT c1.* 
				FROM delivery_customer c1
				INNER JOIN delivery_order_ticket c2 ON c1.id = c2.customer_id
				WHERE c2.code=:code
				";
		$command = Yii::app()->db->createCommand($sql);
		$command->bindParam(':code', $ticketCode, PDO::PARAM_STR);
		return $command->queryRow();
	}
}